package com.yanqu.road.server.cmd.activity.twins.cross;

import com.yanqu.road.entity.activity.twins.config.TwinsConfig;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.TwinsProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.twins.TwinsModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.twins.TwinsMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.property.PropertyHelper;

@Cmd(code = GameProtocol.S_TWINS_CROSS_GET_REWARD, desc = "")
public class CrossTwinsGetSewardCmd extends AbstractCommand {

    TwinsProto.TwinsPvpGetRewardRespMsg reqMsg;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = TwinsProto.TwinsPvpGetRewardRespMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        TwinsConfig config = TwinsMgr.getConfig();
        if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        int checkGroup = player.getModule(TwinsModule.class).checkGroup();
        if (checkGroup != 0) {
            ret = checkGroup;
            return;
        }
        String reward = reqMsg.getReward();
        String killReward = reqMsg.getKillReward();
        player.getModule(CurrencyModule.class)
                .addCurrency(PropertyHelper.parseStringToProperty(reward), eLogMoneyType.Twins,eLogMoneyType.TwinsPvpGetScoreReward);

        player.getModule(CurrencyModule.class)
                .addCurrency(PropertyHelper.parseStringToProperty(killReward), eLogMoneyType.Twins,eLogMoneyType.TwinsPvpGetKillReward);


        player.sendPacket(ClientProtocol.U_TWINS_PVP_GET_REWARD, reqMsg.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret == 0) {
            return;
        }
        player.sendPacket(ClientProtocol.U_TWINS_PVP_GET_REWARD, reqMsg.toBuilder());
    }
}
